package com.tkjt.pms.calc.formula.java.impl;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.tkjt.pms.calc.formula.common.EngineResult;
import com.tkjt.pms.calc.formula.java.KpiJavaFormula;
import com.tkjt.pms.calc.formula.java.common.FaCalcuConsts;
import com.tkjt.pms.calc.formula.java.common.FaDoubleUtil;
import com.tkjt.pms.common.IndexParam;

/***************************************************************
 * 
 * Demo : 示例JAVA公式类
 *
 */
@Service("kpiFormulaDemo")
public class KpiFormulaIncomeMBZ01 implements KpiJavaFormula {
    private Logger logger = LoggerFactory.getLogger(getClass());
	/**
	 * describe:
	 * *@1  收入 - 所有目标值
     * *@2  收入 - 所有实际值
     * *@3  净利润 - 非联考目标值
     * *@4  净利润 - 非联考实际值
     * *@5  净新增达成   目标值
     * *@6  净新增达成   实际值
     * 
	 * *formula: 
	 * *  1) ∑月份列值i
	 * *  2)  计算所有1-12月份汇总 以及季度
     *
     * *@param:
     *         key:param1  Map<String, Double>  1-12月列基础值
     *                  
     * */
    @SuppressWarnings("all")
	@Override
	public EngineResult executor(IndexParam indexParam) {
    	EngineResult result = new EngineResult();
        result.setRetCode(FaCalcuConsts.RET_SUCCESS);
        result.setRetMsg(FaCalcuConsts.RET_SUCCESS);
		try {
            Map<String, Double> mons = (Map<String, Double>) indexParam.getParam(FaCalcuConsts.ITEM_PARAM);
            if (mons == null) {
                result.setRetCode(FaCalcuConsts.RET_MISS_DATA);
                result.setRetMsg("miss param");
                return result;
            }
            Double q01 =0.00;
            q01 += mons.get("m01");
            q01 += mons.get("m02");
            q01 += mons.get("m03");
            Double q02 =0.00;
            q02 += mons.get("m04");
            q02 += mons.get("m05");
            q02 += mons.get("m06");
            Double q03 =0.00;
            q03 += mons.get("m07");
            q03 += mons.get("m08");
            q03 += mons.get("m09");
            Double q04 =0.00;
            q04 += mons.get("m10");
            q04 += mons.get("m11");
            q04 += mons.get("m12");
            Double mTotal=q01+q02+q03+q04;
            Map<String, Double> retValues = new HashMap<>();
            retValues.put("q01", FaDoubleUtil.getDouble(q01));
            retValues.put("q02",FaDoubleUtil.getDouble(q02));
            retValues.put("q03",FaDoubleUtil.getDouble(q03));
            retValues.put("q04",FaDoubleUtil.getDouble(q04));
            retValues.put("mTotal",FaDoubleUtil.getDouble(mTotal));
        }catch (Exception e){
		    logger.error("System program running error",e);
            e.printStackTrace();
            result.setRetCode(FaCalcuConsts.RET_FAIL);
            result.setRetMsg(FaCalcuConsts.RET_FAIL);
        }
		return result;
	}

}
